use "R:\Active\mcbs\Stata\data\mcbs_cohort_2015_2019", clear
rename *, lower /* making all var names lower case */

gen cy2015=1 if cl_yr==2015
replace cy2015=0 if missing(cy2015)
gen cy2016=1 if cl_yr==2016
replace cy2016=0 if missing(cy2016)
gen cy2017=1 if cl_yr==2017
replace cy2017=0 if missing(cy2017)
gen cy2018=1 if cl_yr==2018
replace cy2018=0 if missing(cy2018)
gen cy2019=1 if cl_yr==2019
replace cy2019=0 if missing(cy2019)

destring ssa_scty, gen(ssa_scty2)
destring hrr, gen(hrr2)
destring mbrst, gen(mbrst2)

/* rural vs. urban */
gen rural=1 if ruca_rural==1 | ruca_micro==1
replace rural=0 if ruca_metro==1
gen urban=1 if ruca_metro==1
replace urban=0 if ruca_rural==1 | ruca_micro==1

/* make hispanic mutually exclusive from other races by setting them =0 when hispanic =1 */
replace white=0 if hispanic==1
replace asian=0 if hispanic==1
replace mixed=0 if hispanic==1
replace hawpac=0 if hispanic==1
replace other=0 if hispanic==1
replace black=0 if hispanic==1
replace ntvam=0 if hispanic==1

/* create an other race/ethnicity category of the smallest groups (aipi + ntvam + mixed_oth) */
gen other_rc_eth=1 if asian==1 | hawpac==1 | ntvam==1 | mixed==1 | other==1
replace other_rc_eth=0 if white==1 | black==1 | hispanic==1

/* education */
gen ednothr=1 if ednohs==1 | edunkn==1
replace ednothr=0 if missing(ednothr)
gen edhsgrd=1 if edhsgd==1 | edsmcl==1
replace edhsgrd=0 if missing(edhsgrd)

/* payment model inds */
replace shsv_aco=0 if missing(shsv_aco)
replace nxgn_aco=0 if missing(nxgn_aco)
gen aco=0
replace aco=1 if shsv_aco==1 | nxgn_aco==1

gen em_prim_care = em_pcp + em_apn + em_ger

gen inst=mcbs_inst

/* create one-year lags on my independent variables that I am going to use in my regressions */
sort baseid cl_yr
/* set lag variable if the prior year baseline id exists and if the prior year covariate data occurs 1 year before the current year */
gen cogimp_sr_t1=cogimp_sr if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ad_t1=ad[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen alzdmt_sr_t1=alzdmt_sr[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ad_dx_pryr_t1=ad_dx_pryr[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ad_dx_t1=ad_dx[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ad_dx_ccw_t1=ad_dx_ccw[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen dp_dx_t1=dp_dx[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen anx_dx_t1=anx_dx[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen sp_dx_ccw_t1=sp_dx_ccw[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen aco_t1=aco[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen shsv_aco_t1=shsv_aco[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen nxgn_aco_t1=nxgn_aco[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen age_0101_t1=age_0101[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen male_t1=male[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen black_t1=black[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen hispanic_t1=hispanic[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen white_t1=white[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen other_rc_eth_t1=other_rc_eth[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen vet_sts_t1=vet_sts[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen mcaid_any_t1=mcaid_any[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen prvsup_t1=prvsup[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen fpl_gt200_t1=fpl_gt200[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen fpl_lte100_t1=fpl_lte100[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen fpl_101_200_t1=fpl_101_200[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ednothr_t1=ednothr[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen edhsgrd_t1=edhsgrd[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen edclgd_t1=edclgd[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen married_t1=married[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen live_alon_t1=live_alon[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen psych_rp_t1=psych_rp[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen hcc_score_t1=hcc_score[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen esrd_t1=esrd[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen inst_t1=inst[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen adl_t1=adl[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen iadl_t1=iadl[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen rural_t1=rural[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen urban_t1=urban[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen cty_ma_pen_t1=cty_ma_pen[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ffs_mm_t1=ffs_mm[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen mbrst2_t1=mbrst2[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen sv_xsee_wgt_t1=sv_xsee_wgt[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ma_flag_t1=ma_flag[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen usrd_t1=usrd[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1
gen ssa_scty2_t1=ssa_scty2[_n-1] if baseid==baseid[_n-1] & cl_yr-cl_yr[_n-1]==1 

/* Inclusion1: Age 65+ in U.S.County with at least 12 months of baseline ffs and 12 months study period enrollment or died in study period */
gen st_incl1=1 if sv_xsee_wgt !=. & usrd==1 & age_0101_t1 >=65 & ffs_mm_t1==12 & (ffs_mm==12 | died==1) & ma_flag==0 
replace st_incl1=0 if missing(st_incl1)

/* Inclusion2: + ACO eligible PCS Visit + not in MD or VT  */
gen st_incl2=1 if st_incl1==1 & aco_em_elg==1 & mbrst2!=21 & mbrst2!=46
replace st_incl2=0 if missing(st_incl2)

gen missing_vars=1 if age_0101_t1==. | male_t1==. | white_t1==. | black_t1==. | hispanic_t1==. | other_rc_eth_t1==. /// /* demographic vars */
| mcaid_any_t1==. | vet_sts_t1==. | prvsup_t1==. | esrd_t1==. ///					/* insurance vars */
| fpl_lte100_t1==. | ednothr_t1==. | edhsgrd_t1==. | edclgd_t1==. | married_t1==. ///								/* social risk vars */
| hcc_score_t1==. | inst_t1==. | ad_dx_ccw_t1==. | ad_dx_pryr_t1==. | ad_dx_t1==. /// /* health risk vars */
| rural_t1==. | cty_ma_pen_t1==.   /* area vars */
replace missing_vars=0 if missing(missing_vars)

gen ytonyt1=1 if st_incl2==1 & missing_vars !=1
replace ytonyt1=0 if missing(ytonyt1)

/* Creating adrd variable dummy variables */
gen adrd_t1=1 if alzdmt_sr_t1==1 | ad_dx_pryr_t1==1 | ad_dx_t1==1 | ad_dx_ccw_t1==1 | ad_t1==1 /* counts adrd as self-reported or diagnosed in the baseline year or a prior-year diagnosis in CCW */
replace adrd_t1=0 if missing(adrd_t1)

/* creating mental health dummy variable */
gen mental_t1=1 if psych_rp_t1==1 | dp_dx_t1==1 | anx_dx_t1==1 | sp_dx_ccw_t1==1
replace mental_t1=0 if missing(mental_t1)

gen ytonyt1_adrd=1 if ytonyt1==1 & adrd_t1==1
replace ytonyt1_adrd=0 if missing(ytonyt1_adrd)

/* Figure 1 - study pop flow chart - raw unweighted */
fsum st_incl1 st_incl2 ytonyt1, ///
stats(n sum mean) format(12.4) uselabel

count if st_incl1==1 & st_incl2==0 /* 1545 */
count if st_incl1==1 & st_incl2==0 & aco_em_elg !=1 & em_pcp<1 /* 1328 */
count if st_incl1==1 & st_incl2==0 & (mbrst2==21 | mbrst2==46) /* 217 */

fsum adrd_t1 if st_incl1==1, ///
stats(n sum mean) format(12.4) uselabel
fsum adrd_t1 if st_incl2==1, ///
stats(n sum mean) format(12.4) uselabel
fsum adrd_t1 if ytonyt1==1, ///
stats(n sum mean) format(12.4) uselabel

egen x=group(baseid) if ytonyt1==1 & adrd_t1==1
sum x
egen y=group(baseid) if ytonyt1==1 & adrd_t1 !=1
sum y

/* study pop flow chart - weighted */
svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 
svy: total st_incl1 st_incl2 ytonyt1
estimates table, b(%11.1f)
svy, subpop(if st_incl1==1): total adrd_t1 
estimates table, b(%11.1f)
svy, subpop(if st_incl2==1): total adrd_t1 
estimates table, b(%11.1f)
svy, subpop(if ytonyt1==1): total adrd_t1 
estimates table, b(%11.1f)

/* creating age cut points */
gen age65t74_t1=1 if (age_0101_t1 >=65 & age_0101_t1 <75) 
replace age65t74_t1=0 if missing(age65t74_t1)
gen age75t84_t1=1 if (age_0101_t1 >=75 & age_0101_t1 <85) 
replace age75t84_t1=0 if missing(age75t84_t1)
gen age85pl_t1=1 if age_0101_t1 >=85
replace age85pl_t1=0 if missing(age85pl_t1)

/* Care Fragmentation Scores = 1-BB COC score */
gen frag_scr = 1-coc_scr if em_ttl>=2
gen hi_frag=1 if frag_scr >=0.85 & em_ttl>=2
replace hi_frag=0 if missing(hi_frag) & em_ttl>=2

gen pcp_frag_scr = 1-coc_pcp_scr if em_prim_care>=2 & coc_pcp_scr !=.
gen hi_pcp_frag=1 if pcp_frag_scr >=0.85 & em_prim_care>=2 & coc_pcp_scr !=.
replace hi_pcp_frag=0 if missing(hi_pcp_frag) & em_prim_care>=2 & coc_pcp_scr !=.

/* setting up ambulatory care dummy variables */
gen ad_em=1 if ad_em_vs>=1
replace ad_em=0 if missing(ad_em)
gen awv=1 if awv_ttl>=1
replace awv=0 if missing(awv)
gen pcp=1 if em_prim_care>=1
replace pcp=0 if em_prim_care==0
gen scp=1 if em_scp>=1
replace scp=0 if em_scp==0
gen ger=1 if em_ger>=1
replace ger=0 if missing(ger)
gen psychia=1 if em_psychia>=1
replace psychia=0 if missing(psychia)
gen neuro=1 if em_neuro>=1
replace neuro=0 if missing(neuro)
gen em_home=1 if em_home_vs>=1
replace em_home=0 if missing(em_home)

gen pcp_apn=1 if em_apn>=1
replace pcp_apn=0 if missing(pcp_apn)
gen pcp_phy=1 if em_pcp>=1 | em_ger>=1
replace pcp_phy=0 if missing(pcp_phy)
gen fqrhc=1 if em_fqrhc>=1
replace fqrhc=0 if missing(fqrhc)

gen ffs_mm_wt = ffs_mm / 12  /* creating a weight for each study member based on their #of member months in the study period - will use this to weight the regressions */
gen new_weight = ffs_mm_wt*sv_xsee_wgt


/* Figure 2 - ACO Enrollment Rates in ADRD vs non-ADRD */
svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 

/* global macros to call for risk adjustment */
global x_demo "age_0101_t1 age75t84_t1 age85pl_t1 male_t1 black_t1 hispanic_t1 other_rc_eth_t1 vet_sts_t1" /* age65t74_t1 female white */
global x_ins "mcaid_any_t1 prvsup_t1"  
global x_social "fpl_lte100_t1 fpl_101_200_t1 ednothr_t1 edhsgrd_t1 married_t1" /* fpl_gt200 edclgd */
global x_health "hcc_score_t1 inst_t1 esrd_t1 mental_t1" /* adl_0 iadl_0 esrd_t1 inst_t1  */
global x_area "rural_t1 cty_ma_pen_t1" /* urban_t1 */
global x_time "cy2017 cy2018 cy2019"

/* Any ACO (All) */
svy, subpop(if ytonyt1==1 & adrd_t1==1): mean aco
svy, subpop(if ytonyt1==1 & adrd_t1==0): mean aco
svy, subpop(if ytonyt1==1): regress aco i.adrd_t1

/* Any ACO Joiners (Among Baseline No ACO) */
svy, subpop(if ytonyt1==1 & adrd_t1==1 & aco_t1==0): mean aco
svy, subpop(if ytonyt1==1 & adrd_t1==0 & aco_t1==0): mean aco
svy, subpop(if ytonyt1==1 & aco_t1==0): regress aco i.adrd_t1

/* Any ACO Leavers (Among Baseline ACO)*/
gen noaco=1-aco
svy, subpop(if ytonyt1==1 & adrd_t1==1 & aco_t1==1): mean noaco
svy, subpop(if ytonyt1==1 & adrd_t1==0 & aco_t1==1): mean noaco
svy, subpop(if ytonyt1==1 & aco_t1==1): regress noaco i.adrd_t1

/* Any ACO (All) Risk Adjusted */
svy, subpop(if ytonyt1==1): logit aco i.adrd_t1 aco_t1 $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(adrd_t1) atmeans subpop(if ytonyt1==1) vce(unconditional)
margins adrd_t1, atmeans subpop(if ytonyt1==1) vce(unconditional) post 	/* to get risk adjusted numbers */
test _b[0.adrd_t1 ] = _b[1.adrd_t1]							 			/* to get p-value on diff between two risk adjusted numbers */

/* Any ACO Joiners (Among Baseline No ACO) Risk Adjusted  */
svy, subpop(if ytonyt1==1 & aco_t1==0): logit aco i.adrd_t1 $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(adrd_t1) atmeans subpop(if ytonyt1==1 & aco_t1==0) vce(unconditional)
margins adrd_t1, atmeans subpop(if ytonyt1==1 & aco_t1==0) vce(unconditional) post 	/* to get risk adjusted numbers */
test _b[0.adrd_t1 ] = _b[1.adrd_t1]	

/* Any ACO Leavers (Among Baseline ACO)*/
svy, subpop(if ytonyt1==1 & aco_t1==1): logit noaco i.adrd_t1 $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(adrd_t1) atmeans subpop(if ytonyt1==1 & aco_t1==1) vce(unconditional)				
margins adrd_t1, atmeans subpop(if ytonyt1==1 & aco_t1==1) vce(unconditional) post 	/* to get risk adjusted numbers */
test _b[0.adrd_t1 ] = _b[1.adrd_t1]	


/* Appendix Table 1 - Comparing Study Sample to Excluded sample */
svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 
/* global macros to call */
global x_demo "age_0101_t1 age65t74_t1 age75t84_t1 age85pl_t1 male_t1 black_t1 hispanic_t1 white_t1 other_rc_eth_t1 vet_sts_t1" 
global x_ins "mcaid_any_t1 prvsup_t1"  
global x_social "fpl_lte100_t1 fpl_101_200_t1 fpl_gt200_t1 ednothr_t1 edhsgrd_t1 edclgd_t1 married_t1" 
global x_health "hcc_score_t1 inst_t1 esrd_t1 mental_t1" 
global x_area "rural_t1 urban_t1 cty_ma_pen_t1"
global x_time "cy2016 cy2017 cy2018 cy2019"

svy, subpop(if ytonyt1==1): mean adrd_t1 aco
svy, subpop(if ytonyt1==1): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd

gen excluded=1 if st_incl2==1 & ytonyt1 !=1
replace excluded=0 if ytonyt1==1

svy, subpop(if excluded==1): mean adrd_t1 ad_t1 aco
svy, subpop(if excluded==1): mean alzdmt_sr_t1 
svy, subpop(if excluded==1): mean ad_dx_pryr_t1 
svy, subpop(if excluded==1): mean ad_dx_ccw_t1
svy, subpop(if excluded==1): mean ad_dx_t1 

svy, subpop(if excluded==1): mean age_0101_t1 age65t74_t1 age75t84_t1 age85pl_t1
estat sd
svy, subpop(if excluded==1): mean male_t1
svy, subpop(if excluded==1): mean black_t1 hispanic_t1 white_t1 other_rc_eth_t1
svy, subpop(if excluded==1): mean vet_sts_t1
svy, subpop(if excluded==1): mean mcaid_any_t1
svy, subpop(if excluded==1): mean prvsup_t1
svy, subpop(if excluded==1): mean fpl_lte100_t1 fpl_101_200_t1 fpl_gt200_t1
svy, subpop(if excluded==1): mean ednothr_t1 edhsgrd_t1 edclgd_t1
svy, subpop(if excluded==1): mean married_t1
svy, subpop(if excluded==1): mean hcc_score_t1
estat sd
svy, subpop(if excluded==1): mean esrd_t1
svy, subpop(if excluded==1): mean inst_t1
svy, subpop(if excluded==1): mean mental_t1
svy, subpop(if excluded==1): mean rural_t1 urban_t1
svy, subpop(if excluded==1): mean cty_ma_pen_t1
   
svy, subpop(if (ytonyt1==1 | excluded==1)): logit adrd_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit aco ytonyt1
testparm ytonyt1
   
svy, subpop(if (ytonyt1==1 | excluded==1)): regress age_0101_t1 ytonyt1
testparm ytonyt1

gen age_cat_t1 = 1 if age65t74_t1==1
replace age_cat_t1 = 2 if age75t84_t1==1
replace age_cat_t1 = 3 if age85pl_t1==1
svy, subpop(if (ytonyt1==1 | excluded==1)): logit ytonyt1 i.age_cat_t1
testparm i.age_cat_t1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit male_t1 ytonyt1
testparm ytonyt1

gen rceth_cat_t1 = 1 if black_t1==1
replace rceth_cat_t1 = 2 if hispanic_t1==1
replace rceth_cat_t1 = 3 if white_t1==1
replace rceth_cat_t1 = 4 if other_rc_eth_t1==1
svy, subpop(if (ytonyt1==1 | excluded==1)): logit ytonyt1 i.rceth_cat_t1
testparm i.rceth_cat_t1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit vet_sts_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit mcaid_any_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit prvsup_t1 ytonyt1
testparm ytonyt1

gen inc_cat_t1 = 1 if fpl_lte100_t1==1
replace inc_cat_t1 = 2 if fpl_101_200_t1==1
replace inc_cat_t1 = 3 if fpl_gt200_t1==1
svy, subpop(if (ytonyt1==1 | excluded==1)): logit ytonyt1 i.inc_cat_t1
testparm i.inc_cat_t1

gen ed_cat_t1 = 1 if ednothr_t1==1
replace ed_cat_t1 = 2 if edhsgrd_t1==1
replace ed_cat_t1 = 3 if edclgd_t1==1
svy, subpop(if (ytonyt1==1 | excluded==1)): logit ytonyt1 i.ed_cat_t1
testparm i.ed_cat_t1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit married_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): regress hcc_score_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit inst_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit esrd_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit mental_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): logit rural_t1 ytonyt1
testparm ytonyt1

svy, subpop(if (ytonyt1==1 | excluded==1)): regress cty_ma_pen_t1 ytonyt1
testparm ytonyt1


/* appendix figure 2 - baseline+study period  community dwelling only + non-decedents in study period */
/* Any ACO (All) */
svy, subpop(if ytonyt1==1 & adrd_t1==1 & inst_t1==0 & inst==0 & died==0): mean aco
svy, subpop(if ytonyt1==1 & adrd_t1==0 & inst_t1==0 & inst==0 & died==0): mean aco
svy, subpop(if ytonyt1==1 & inst_t1==0 & inst==0 & died==0): regress aco i.adrd_t1

/* Any ACO Joiners (Among Baseline No ACO) */
svy, subpop(if ytonyt1==1 & adrd_t1==1 & aco_t1==0 & inst_t1==0 & inst==0 & died==0): mean aco
svy, subpop(if ytonyt1==1 & adrd_t1==0 & aco_t1==0 & inst_t1==0 & inst==0 & died==0): mean aco
svy, subpop(if ytonyt1==1 & aco_t1==0 & inst_t1==0 & inst==0 & died==0): regress aco i.adrd_t1

/* Any ACO (Among Baseline ACO)*/
svy, subpop(if ytonyt1==1 & adrd_t1==1 & aco_t1==1 & inst_t1==0 & inst==0 & died==0): mean noaco
svy, subpop(if ytonyt1==1 & adrd_t1==0 & aco_t1==1 & inst_t1==0 & inst==0 & died==0): mean noaco
svy, subpop(if ytonyt1==1 & aco_t1==1 & inst_t1==0 & inst==0 & died==0): regress noaco i.adrd_t1

/* Any ACO (All) */
svy, subpop(if st_incl2==1 & adrd_t1==1): mean aco
svy, subpop(if st_incl2==1 & adrd_t1==0): mean aco
svy, subpop(if st_incl2==1): regress aco i.adrd_t1

/* Any ACO Joiners (Among Baseline No ACO) */
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco_t1==0): mean aco
svy, subpop(if st_incl2==1 & adrd_t1==0 & aco_t1==0): mean aco
svy, subpop(if st_incl2==1 & aco_t1==0): regress aco i.adrd_t1

/* Any ACO Leavers (Among Baseline ACO)*/
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco_t1==1): mean noaco
svy, subpop(if st_incl2==1 & adrd_t1==0 & aco_t1==1): mean noaco
svy, subpop(if st_incl2==1 & aco_t1==1): regress noaco i.adrd_t1

	

/* Table 1: descriptives by aco vs no aco among ADRD */
/* global macros to call */
global x_demo "age_0101_t1 age65t74_t1 age75t84_t1 age85pl_t1 male_t1 black_t1 hispanic_t1 white_t1 other_rc_eth_t1 vet_sts_t1" 
global x_ins "mcaid_any_t1 prvsup_t1"  
global x_social "fpl_lte100_t1 fpl_101_200_t1 fpl_gt200_t1 ednothr_t1 edhsgrd_t1 edclgd_t1 married_t1" 
global x_health "hcc_score_t1 inst_t1 esrd_t1 mental_t1" 
global x_area "rural_t1 urban_t1 cty_ma_pen_t1"
global x_time "cy2017 cy2018 cy2019"

svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 
svy, subpop(if ytonyt1_adrd==1): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd
svy, subpop(if ytonyt1_adrd==1 & aco==1): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd

/* with simple bi-variate wald test get regression p-value for Wald Test same as anova/F-stata for continuous dependent variables or chi-squared for categorical */

svy, subpop(if ytonyt1_adrd==1): regress age_0101_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit aco i.age_cat_t1
testparm i.age_cat_t1

svy, subpop(if ytonyt1_adrd==1): logit male_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit aco i.rceth_cat_t1
testparm i.rceth_cat_t1

svy, subpop(if ytonyt1_adrd==1): logit vet_sts_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit mcaid_any_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit prvsup_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit aco i.inc_cat_t1
testparm i.inc_cat_t1

svy, subpop(if ytonyt1_adrd==1): logit aco i.ed_cat_t1
testparm i.ed_cat_t1

svy, subpop(if ytonyt1_adrd==1): logit married_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): regress hcc_score_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit esrd_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit inst_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit mental_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): logit rural_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1): regress cty_ma_pen_t1 aco
testparm aco

/* Appendix Table 2: institutionalization and death in study year by aco enrollment */
/* Entire sample */
svy, subpop(if ytonyt1==1 & aco==1): mean inst died
svy, subpop(if ytonyt1==1 & aco==0): mean inst died
svy, subpop(if ytonyt1==1): logit inst aco
testparm aco
svy, subpop(if ytonyt1==1): logit died aco
testparm aco

/* dementia sample */
svy, subpop(if ytonyt1_adrd==1 & aco==1): mean inst died
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean inst died
svy, subpop(if ytonyt1_adrd==1): logit inst aco
testparm aco
svy, subpop(if ytonyt1_adrd==1): logit died aco
testparm aco

/* Appendix Exhibit 3 (table): descriptives by aco vs no aco exit among ADRD */
svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 
svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd
svy, subpop(if ytonyt1_adrd==1 & aco_t1==1 & aco==0): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd
svy, subpop(if ytonyt1_adrd==1 & aco_t1==1 & aco==1): mean $x_demo $x_ins $x_social $x_health $x_area $x_time
estat sd


/* with simple bi-variate wald test get regression p-value for Wald Test same as anova/F-stata for continuous dependent variables or chi-squared for categorical */

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): regress age_0101_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit aco i.age_cat_t1
testparm i.age_cat_t1

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit male_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit aco i.rceth_cat_t1
testparm i.rceth_cat_t1

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit vet_sts_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit mcaid_any_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit prvsup_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit aco i.inc_cat_t1
testparm i.inc_cat_t1

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit aco i.ed_cat_t1
testparm i.ed_cat_t1

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit married_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): regress hcc_score_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit esrd_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit inst_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit mental_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): logit rural_t1 aco
testparm aco

svy, subpop(if ytonyt1_adrd==1 & aco_t1==1): regress cty_ma_pen_t1 aco
testparm aco

/* Table 2: ADRD-related Care by ACO attribution */
svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 

/* Unadjusted Outcomes for Study Sample */
svy, subpop(if ytonyt1_adrd==1): mean ad_em
svy, subpop(if ytonyt1_adrd==1): mean ger
svy, subpop(if ytonyt1_adrd==1): mean neuro
svy, subpop(if ytonyt1_adrd==1): mean psychia
svy, subpop(if ytonyt1_adrd==1): mean pcp
svy, subpop(if ytonyt1_adrd==1): mean awv
svy, subpop(if ytonyt1_adrd==1): mean em_home

/* Unadjusted Outcomes by ACO attribution */
svy, subpop(if ytonyt1_adrd==1 & aco==1): mean ad_em
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean ad_em
svy, subpop(if ytonyt1_adrd==1): regress ad_em i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & aco==1): mean ger
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean ger
svy, subpop(if ytonyt1_adrd==1): regress ger i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & aco==1): mean neuro
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean neuro
svy, subpop(if ytonyt1_adrd==1): regress neuro i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & aco==1): mean psychia
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean psychia
svy, subpop(if ytonyt1_adrd==1): regress psychia i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & aco==1): mean pcp
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean pcp
svy, subpop(if ytonyt1_adrd==1): regress pcp i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & aco==1): mean awv
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean awv
svy, subpop(if ytonyt1_adrd==1): regress awv i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & aco==1): mean em_home
svy, subpop(if ytonyt1_adrd==1 & aco==0): mean em_home
svy, subpop(if ytonyt1_adrd==1): regress em_home i.aco
testparm i.aco

/* Adjusted Outcomes by ACO attribution */
svyset sv_varpsu [pw=new_weight], strata(sv_varstratum) singleunit(centered) || baseid 
/* global macros to call */
global x_demo "age_0101_t1 age75t84_t1 age85pl_t1 male_t1 black_t1 hispanic_t1 other_rc_eth_t1 vet_sts_t1" /* age65t74_t1 female white */
global x_ins "mcaid_any_t1 prvsup_t1"  
global x_social "fpl_lte100_t1 fpl_101_200_t1 ednothr_t1 edhsgrd_t1 married_t1" /* fpl_gt200 edclgd */
global x_health "hcc_score_t1 inst_t1 esrd_t1 mental_t1" /*  */
global x_area "rural_t1 cty_ma_pen_t1" /* urban_t1 */
global x_time "cy2017 cy2018 cy2019"

svy, subpop(if ytonyt1_adrd==1): logit ad_em i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1): logit ger i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1): logit neuro i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1): logit psychia i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1): logit pcp i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1): logit awv i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1): logit em_home i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, or 
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1) vce(unconditional) 


/* Table 3: Care Fragmentation by ACO attribution */
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2): mean pcp_frag_scr
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2): mean hi_pcp_frag
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): mean em_prim_care
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): mean dstnct_pcp
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): mean dstnct_apn
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): mean frag_scr
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): mean hi_frag
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): mean em_ttl
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): mean dstnct_clin
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): mean dstnct_scp

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==1): mean pcp_frag_scr
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==0): mean pcp_frag_scr
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2): regress pcp_frag_scr i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==1): mean hi_pcp_frag
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==0): mean hi_pcp_frag
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2): regress hi_pcp_frag i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==1 & pcp_frag_scr !=.): mean em_prim_care
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==0 & pcp_frag_scr !=.): mean em_prim_care
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): regress em_prim_care i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==1 & pcp_frag_scr !=.): mean dstnct_pcp
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==0 & pcp_frag_scr !=.): mean dstnct_pcp
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): regress dstnct_pcp i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==1 & pcp_frag_scr !=.): mean dstnct_apn
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & aco==0 & pcp_frag_scr !=.): mean dstnct_apn
svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): regress dstnct_apn i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==1): mean frag_scr
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==0): mean frag_scr
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): regress frag_scr i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==1): mean hi_frag
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==0): mean hi_frag
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): regress hi_frag i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==1): mean em_ttl
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==0): mean em_ttl
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): regress em_ttl i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==1): mean dstnct_clin
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==0): mean dstnct_clin
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): regress dstnct_clin i.aco
testparm i.aco

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==1): mean dstnct_scp
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2 & aco==0): mean dstnct_scp
svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): regress dstnct_scp i.aco
testparm i.aco

/* Adjusted Outcomes by ACO attribution */
svyset sv_varpsu [pw=new_weight], strata(sv_varstratum) singleunit(centered) || baseid 
/* global macros to call */
global x_demo "age_0101_t1 age75t84_t1 age85pl_t1 male_t1 black_t1 hispanic_t1 other_rc_eth_t1 vet_sts_t1" /* age65t74_t1 female white */
global x_ins "mcaid_any_t1 prvsup_t1"  
global x_social "fpl_lte100_t1 fpl_101_200_t1 ednothr_t1 edhsgrd_t1 married_t1" /* fpl_gt200 edclgd */
global x_health "hcc_score_t1 inst_t1 esrd_t1 mental_t1" /*  */
global x_area "rural_t1 cty_ma_pen_t1" /* urban_t1 */
global x_time "cy2017 cy2018 cy2019"

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2): regress pcp_frag_scr i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_prim_care

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2): logit hi_pcp_frag i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_prim_care, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_prim_care>=2) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): nbreg em_prim_care i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, irr
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): nbreg dstnct_pcp i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_prim_care, irr
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.): nbreg dstnct_apn i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_prim_care, irr
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_prim_care>=2 & pcp_frag_scr !=.) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): regress frag_scr i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_ttl

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): logit hi_frag i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_ttl, or
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_ttl>=2) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): nbreg em_ttl i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time, irr
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_ttl>=2) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): nbreg dstnct_clin i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_ttl, irr
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_ttl>=2) vce(unconditional) 

svy, subpop(if ytonyt1_adrd==1 & em_ttl>=2): nbreg dstnct_scp i.aco $x_demo $x_ins $x_social $x_health $x_area $x_time em_ttl, irr
margins, dydx(aco) atmeans subpop(if ytonyt1_adrd==1 & em_ttl>=2) vce(unconditional) 


/* Appendix Table 4: ADRD-related Care by ACO attribution -- larger sample including patients excluded for missing data */
svyset sv_varpsu [pw=sv_xsee_wgt], strata(sv_varstratum) singleunit(centered) || baseid 

/* Unadjusted Outcomes for Study Sample */
svy, subpop(if st_incl2==1 & adrd_t1==1): mean ad_em
svy, subpop(if st_incl2==1 & adrd_t1==1): mean ger
svy, subpop(if st_incl2==1 & adrd_t1==1): mean neuro
svy, subpop(if st_incl2==1 & adrd_t1==1): mean psychia
svy, subpop(if st_incl2==1 & adrd_t1==1): mean pcp
svy, subpop(if st_incl2==1 & adrd_t1==1): mean awv
svy, subpop(if st_incl2==1 & adrd_t1==1): mean em_home

/* Unadjusted Outcomes by ACO attribution */
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean ad_em
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean ad_em
svy, subpop(if st_incl2==1 & adrd_t1==1): regress ad_em i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean ger
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean ger
svy, subpop(if st_incl2==1 & adrd_t1==1): regress ger i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean neuro
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean neuro
svy, subpop(if st_incl2==1 & adrd_t1==1): regress neuro i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean psychia
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean psychia
svy, subpop(if st_incl2==1 & adrd_t1==1): regress psychia i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean pcp
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean pcp
svy, subpop(if st_incl2==1 & adrd_t1==1): regress pcp i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean awv
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean awv
svy, subpop(if st_incl2==1 & adrd_t1==1): regress awv i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==1): mean em_home
svy, subpop(if st_incl2==1 & adrd_t1==1 & aco==0): mean em_home
svy, subpop(if st_incl2==1 & adrd_t1==1): regress em_home i.aco
testparm i.aco


/* Appendix Table 5: Care Fragmentation by ACO attribution -- Largere sample*/
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2): mean pcp_frag_scr
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2): mean hi_pcp_frag
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & pcp_frag_scr !=.): mean em_prim_care
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & pcp_frag_scr !=.): mean dstnct_pcp
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & pcp_frag_scr !=.): mean dstnct_apn
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): mean frag_scr
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): mean hi_frag
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): mean em_ttl
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): mean dstnct_clin
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): mean dstnct_scp

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==1): mean pcp_frag_scr
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==0): mean pcp_frag_scr
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2): regress pcp_frag_scr i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==1): mean hi_pcp_frag
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==0): mean hi_pcp_frag
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2): regress hi_pcp_frag i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==1 & pcp_frag_scr !=.): mean em_prim_care
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==0 & pcp_frag_scr !=.): mean em_prim_care
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & pcp_frag_scr !=.): regress em_prim_care i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==1 & pcp_frag_scr !=.): mean dstnct_pcp
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==0 & pcp_frag_scr !=.): mean dstnct_pcp
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & pcp_frag_scr !=.): regress dstnct_pcp i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==1 & pcp_frag_scr !=.): mean dstnct_apn
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & aco==0 & pcp_frag_scr !=.): mean dstnct_apn
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_prim_care>=2 & pcp_frag_scr !=.): regress dstnct_apn i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==1): mean frag_scr
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==0): mean frag_scr
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): regress frag_scr i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==1): mean hi_frag
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==0): mean hi_frag
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): regress hi_frag i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==1): mean em_ttl
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==0): mean em_ttl
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): regress em_ttl i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==1): mean dstnct_clin
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==0): mean dstnct_clin
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): regress dstnct_clin i.aco
testparm i.aco

svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==1): mean dstnct_scp
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2 & aco==0): mean dstnct_scp
svy, subpop(if st_incl2==1 & adrd_t1==1 & em_ttl>=2): regress dstnct_scp i.aco
testparm i.aco


/***********************************************		END CODE 		*******************************/


